package cn.migu.music.hangupsms.repository;

import cn.migu.music.hangupsms.common.entity.SmsProvinceSwitchSettings;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface SmsProvinceSwitchSettingsMapper {
    @Update(value = "update t_migu_hangup_sms_province_switch set switch_on=#{switchOn}, change_time=#{changeTime}, update_time=now()" +
                    " where province_id=#{provinceId}")
    void updateProvinceSwitch(@Param("provinceId") String provinceId, @Param("switchOn")  int switchOn, @Param("changeTime") LocalDateTime changeTime);

    @Select(value = "select province_id,province_name,switch_on,apply_status,apply_time,change_time,delete_flag,create_time,update_time" +
                    " from t_migu_hangup_sms_province_switch where delete_flag = 0")
    List<SmsProvinceSwitchSettings> getAllSettings();

    @Select(value = "select province_id,province_name,switch_on,apply_status,apply_time,change_time,delete_flag,create_time,update_time" +
                    " from t_migu_hangup_sms_province_switch" +
                    " where province_id=#{provinceId} and delete_flag = 0")
    SmsProvinceSwitchSettings get(@Param("provinceId") String provinceId);

    @Select(value = "select province_id,province_name,switch_on,apply_status,apply_time,change_time,delete_flag,create_time,update_time" +
                    " from t_migu_hangup_sms_province_switch" +
                    " where province_id=#{provinceId}")
    SmsProvinceSwitchSettings getIgnoreDelete(@Param("provinceId") String provinceId);

    @Update(value = "update t_migu_hangup_sms_province_switch" +
                    " set apply_status=#{applyStatus},apply_time=#{applyTime}" +
                    " where province_id=#{provinceId}")
    void updateApplyStatus(@Param("provinceId") String provinceId,@Param("applyStatus") int applyStatus,@Param("applyTime") LocalDateTime applyTime);
}
